# -*- coding: utf-8 -*-
from datetime import datetime
import logging
import re

logger = logging.getLogger("error")


class CheckUtils(object):

    @classmethod
    def check_date(cls, date):
        if isinstance(date, datetime):
            return True
        re_date = re.match(r'^\d{4}/\d{1,2}/\d{1,2}', date)
        if not re_date:
            return False
        return True

    @classmethod
    def check_year(cls, year: str):
        year_match = re.match(r'^\d{4}$', year)
        if not year_match:
            return False
        return True

    @classmethod
    def check_month(cls, month: str):
        try:
            month_match = re.match(r'^\d{1,2}$', str(month))
            if not month_match:
                return False
            if int(month) > 12:
                return False
            return True
        except Exception as e:
            logger.error(repr(e))
            return False

    @classmethod
    def check_number(cls, num):
        try:
            float(num)
        except Exception:
            return False
        return True
